home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2008 April / PCgo 2008-04 (DVD).iso / interface / contents / demoversionen_3846 / 13664 / files / Data1.cab / preview.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2001-10-16  |  24.6 KB  |  730 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  3. Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0"; "COMCTL32.OCX"
  4. Begin VB.Form frmPreview 
  5.    Caption         =   "TurboCAD SDK Demo"
  6.    ClientHeight    =   6840
  7.    ClientLeft      =   3570
  8.    ClientTop       =   1215
  9.    ClientWidth     =   8490
  10.    LinkTopic       =   "Form1"
  11.    PaletteMode     =   1  'UseZOrder
  12.    ScaleHeight     =   6840
  13.    ScaleWidth      =   8490
  14.    Begin ComctlLib.Toolbar Toolbar1 
  15.       Align           =   1  'Align Top
  16.       Height          =   465
  17.       Left            =   0
  18.       TabIndex        =   11
  19.       Top             =   0
  20.       Width           =   8490
  21.       _ExtentX        =   14975
  22.       _ExtentY        =   820
  23.       ButtonWidth     =   741
  24.       ButtonHeight    =   714
  25.       AllowCustomize  =   0   'False
  26.       ImageList       =   "ImageList1"
  27.       _Version        =   327682
  28.       BeginProperty Buttons {0713E452-850A-101B-AFC0-4210102A8DA7} 
  29.          NumButtons      =   6
  30.          BeginProperty Button1 {0713F354-850A-101B-AFC0-4210102A8DA7} 
  31.             Caption         =   ""
  32.             Key             =   "Circle"
  33.             Description     =   ""
  34.             Object.ToolTipText     =   "Add Circle"
  35.             Object.Tag             =   ""
  36.             ImageIndex      =   1
  37.             Style           =   2
  38.          EndProperty
  39.          BeginProperty Button2 {0713F354-850A-101B-AFC0-4210102A8DA7} 
  40.             Caption         =   ""
  41.             Key             =   "Line"
  42.             Description     =   ""
  43.             Object.ToolTipText     =   "Add Line"
  44.             Object.Tag             =   ""
  45.             ImageIndex      =   2
  46.             Style           =   2
  47.          EndProperty
  48.          BeginProperty Button3 {0713F354-850A-101B-AFC0-4210102A8DA7} 
  49.             Caption         =   ""
  50.             Key             =   "Curve"
  51.             Description     =   ""
  52.             Object.ToolTipText     =   "Add Curve"
  53.             Object.Tag             =   ""
  54.             ImageIndex      =   3
  55.             Style           =   2
  56.          EndProperty
  57.          BeginProperty Button4 {0713F354-850A-101B-AFC0-4210102A8DA7} 
  58.             Caption         =   ""
  59.             Key             =   "Star"
  60.             Description     =   ""
  61.             Object.ToolTipText     =   "Add Star"
  62.             Object.Tag             =   ""
  63.             ImageIndex      =   4
  64.             Style           =   2
  65.          EndProperty
  66.          BeginProperty Button5 {0713F354-850A-101B-AFC0-4210102A8DA7} 
  67.             Caption         =   ""
  68.             Key             =   ""
  69.             Description     =   ""
  70.             Object.ToolTipText     =   ""
  71.             Object.Tag             =   ""
  72.             Style           =   3
  73.          EndProperty
  74.          BeginProperty Button6 {0713F354-850A-101B-AFC0-4210102A8DA7} 
  75.             Caption         =   ""
  76.             Key             =   "Select"
  77.             Description     =   ""
  78.             Object.ToolTipText     =   "Select"
  79.             Object.Tag             =   ""
  80.             ImageIndex      =   5
  81.             Style           =   2
  82.          EndProperty
  83.       EndProperty
  84.    End
  85.    Begin VB.CommandButton cmdDraw 
  86.       Caption         =   "Draw"
  87.       Height          =   375
  88.       Left            =   120
  89.       TabIndex        =   10
  90.       Top             =   600
  91.       Width           =   855
  92.    End
  93.    Begin VB.PictureBox Picture1 
  94.       Height          =   4695
  95.       Left            =   120
  96.       ScaleHeight     =   309
  97.       ScaleMode       =   3  'Pixel
  98.       ScaleWidth      =   533
  99.       TabIndex        =   9
  100.       Top             =   1560
  101.       Width           =   8055
  102.    End
  103.    Begin VB.VScrollBar VScroll1 
  104.       Height          =   4695
  105.       LargeChange     =   4000
  106.       Left            =   8160
  107.       Max             =   32000
  108.       SmallChange     =   1000
  109.       TabIndex        =   8
  110.       Top             =   1560
  111.       Width           =   255
  112.    End
  113.    Begin VB.HScrollBar HScroll1 
  114.       Height          =   255
  115.       LargeChange     =   4000
  116.       Left            =   120
  117.       Max             =   32000
  118.       SmallChange     =   1000
  119.       TabIndex        =   7
  120.       Top             =   6240
  121.       Width           =   8055
  122.    End
  123.    Begin VB.ComboBox Combo1 
  124.       Height          =   315
  125.       Left            =   4560
  126.       TabIndex        =   5
  127.       Top             =   600
  128.       Width           =   3855
  129.    End
  130.    Begin VB.CommandButton cmdProperties 
  131.       Caption         =   "Properties"
  132.       Height          =   375
  133.       Left            =   1080
  134.       TabIndex        =   4
  135.       Top             =   600
  136.       Width           =   855
  137.    End
  138.    Begin VB.CommandButton cmdNew 
  139.       Caption         =   "New Drawing"
  140.       Height          =   375
  141.       Left            =   3240
  142.       TabIndex        =   3
  143.       Top             =   1080
  144.       Width           =   1215
  145.    End
  146.    Begin VB.CommandButton cmdZoomPlus 
  147.       Caption         =   "Zoom In"
  148.       Height          =   375
  149.       Left            =   1080
  150.       TabIndex        =   2
  151.       Top             =   1080
  152.       Width           =   855
  153.    End
  154.    Begin VB.CommandButton cmdZoomMinus 
  155.       Caption         =   "Zoom Out"
  156.       Height          =   375
  157.       Left            =   120
  158.       TabIndex        =   1
  159.       Top             =   1080
  160.       Width           =   855
  161.    End
  162.    Begin VB.CommandButton cmdOpen 
  163.       Caption         =   "Open Drawing"
  164.       Height          =   375
  165.       Left            =   3240
  166.       TabIndex        =   0
  167.       Top             =   600
  168.       Width           =   1215
  169.    End
  170.    Begin MSComDlg.CommonDialog CommonDialog1 
  171.       Left            =   4800
  172.       Top             =   960
  173.       _ExtentX        =   847
  174.       _ExtentY        =   847
  175.       _Version        =   393216
  176.       Filter          =   "TurboCAD Files (*.tcw)|*.tcw"
  177.    End
  178.    Begin ComctlLib.StatusBar StatusBar1 
  179.       Align           =   2  'Align Bottom
  180.       Height          =   300
  181.       Left            =   0
  182.       TabIndex        =   6
  183.       Top             =   6540
  184.       Width           =   8490
  185.       _ExtentX        =   14975
  186.       _ExtentY        =   529
  187.       SimpleText      =   ""
  188.       _Version        =   327682
  189.       BeginProperty Panels {0713E89E-850A-101B-AFC0-4210102A8DA7} 
  190.          NumPanels       =   5
  191.          BeginProperty Panel1 {0713E89F-850A-101B-AFC0-4210102A8DA7} 
  192.             AutoSize        =   1
  193.             Object.Width           =   9287
  194.             Text            =   "No drawing"
  195.             TextSave        =   "No drawing"
  196.             Key             =   ""
  197.             Object.Tag             =   ""
  198.          EndProperty
  199.          BeginProperty Panel2 {0713E89F-850A-101B-AFC0-4210102A8DA7} 
  200.             Object.Width           =   1270
  201.             MinWidth        =   1270
  202.             Text            =   "Left"
  203.             TextSave        =   "Left"
  204.             Key             =   ""
  205.             Object.Tag             =   ""
  206.          EndProperty
  207.          BeginProperty Panel3 {0713E89F-850A-101B-AFC0-4210102A8DA7} 
  208.             Object.Width           =   1270
  209.             MinWidth        =   1270
  210.             Text            =   "Top"
  211.             TextSave        =   "Top"
  212.             Key             =   ""
  213.             Object.Tag             =   ""
  214.          EndProperty
  215.          BeginProperty Panel4 {0713E89F-850A-101B-AFC0-4210102A8DA7} 
  216.             Object.Width           =   1270
  217.             MinWidth        =   1270
  218.             Text            =   "Width"
  219.             TextSave        =   "Width"
  220.             Key             =   ""
  221.             Object.Tag             =   ""
  222.          EndProperty
  223.          BeginProperty Panel5 {0713E89F-850A-101B-AFC0-4210102A8DA7} 
  224.             Object.Width           =   1270
  225.             MinWidth        =   1270
  226.             Text            =   "Height"
  227.             TextSave        =   "Height"
  228.             Key             =   ""
  229.             Object.Tag             =   ""
  230.          EndProperty
  231.       EndProperty
  232.    End
  233.    Begin ComctlLib.ImageList ImageList1 
  234.       Left            =   5400
  235.       Top             =   960
  236.       _ExtentX        =   1005
  237.       _ExtentY        =   1005
  238.       BackColor       =   -2147483643
  239.       ImageWidth      =   21
  240.       ImageHeight     =   21
  241.       MaskColor       =   12632256
  242.       _Version        =   327682
  243.       BeginProperty Images {0713E8C2-850A-101B-AFC0-4210102A8DA7} 
  244.          NumListImages   =   5
  245.          BeginProperty ListImage1 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
  246.             Picture         =   "Preview.frx":0000
  247.             Key             =   ""
  248.          EndProperty
  249.          BeginProperty ListImage2 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
  250.             Picture         =   "Preview.frx":018E
  251.             Key             =   ""
  252.          EndProperty
  253.          BeginProperty ListImage3 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
  254.             Picture         =   "Preview.frx":031C
  255.             Key             =   ""
  256.          EndProperty
  257.          BeginProperty ListImage4 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
  258.             Picture         =   "Preview.frx":04AA
  259.             Key             =   ""
  260.          EndProperty
  261.          BeginProperty ListImage5 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
  262.             Picture         =   "Preview.frx":0A3C
  263.             Key             =   ""
  264.          EndProperty
  265.       EndProperty
  266.    End
  267. Attribute VB_Name = "frmPreview"
  268. Attribute VB_GlobalNameSpace = False
  269. Attribute VB_Creatable = False
  270. Attribute VB_PredeclaredId = True
  271. Attribute VB_Exposed = False
  272. '******************************************************************'
  273. '*                                                                *'
  274. '*                      TurboCAD for Windows                      *'
  275. '*                   Copyright (c) 1993 - 2001                    *'
  276. '*             International Microcomputer Software, Inc.         *'
  277. '*                            (IMSI)                              *'
  278. '*                      All rights reserved.                      *'
  279. '*                                                                *'
  280. '******************************************************************'
  281. Option Explicit
  282. 'Global variables
  283. 'SDK objects
  284. Dim TheApp As Object
  285. Dim Drawings As Object
  286. Dim TheDrawing As Object
  287. Dim Views As Object
  288. Dim TheView As Object
  289. 'View parameters
  290. Dim ViewH#, ViewW#, ViewL#, ViewT# 'View coordinates
  291. 'Scroll parameters
  292. Dim ScrollCenterX#, ScrollCenterY# 'Dead center for scrolling
  293. Dim ScrollRangeX#, ScrollRangeY# 'Scroll range
  294. Dim HScrollLast%, VScrollLast% 'Remember last values for use in scrolling
  295. 'Drag and tool states
  296. Dim ActiveTool$
  297. Dim StartX#, StartY#
  298. Dim LeftButtonDown As Boolean
  299. Dim Dragging As Boolean
  300. 'Curve tool
  301. Dim SplineGraphic As Object
  302. Dim SplineVerts As Object
  303. 'Select tool
  304. Dim SelectedGraphic As Object
  305. Dim SavedColor As Variant
  306. Private Sub OnNewDrawing()
  307.     On Error GoTo Errors
  308.     'Update the status bar with new drawing name
  309.     StatusBar1.Panels(1).Text = TheDrawing.Name
  310.     Picture1.BackColor = RGB(255, 255, 255)
  311.     Set Views = TheDrawing.Views
  312.     Set TheView = Views.Add
  313.     ViewW# = 0
  314.     ViewH# = 0
  315.     ViewL# = 0
  316.     ViewT# = 0
  317.     ViewZoomBy 0
  318.     Exit Sub
  319. Errors:
  320.     ReleaseDrawingObjects
  321. End Sub
  322. Private Sub cmdDraw_Click()
  323.     Repaint
  324. End Sub
  325. 'New button handler
  326. Private Sub cmdNew_Click()
  327.     ReleaseDrawingObjects 'Close old drawing, etc.
  328.     Set TheDrawing = Drawings.Add
  329.     OnNewDrawing
  330. End Sub
  331. 'Open button handler
  332. Private Sub cmdOpen_Click()
  333.     Dim FileName$
  334.     CommonDialog1.ShowOpen 'Get .tcw file name
  335.     FileName$ = CommonDialog1.FileName
  336.     If FileName$ = "" Then Exit Sub
  337.     ReleaseDrawingObjects 'Close old drawing, etc.
  338.     Set TheDrawing = Drawings.Open(FileName$)
  339.     OnNewDrawing
  340. End Sub
  341. Private Sub cmdZoomMinus_Click()
  342.     ViewZoomBy 0.707
  343. End Sub
  344. Private Sub cmdZoomPlus_Click()
  345.     ViewZoomBy 1.414
  346. End Sub
  347. Private Sub Form_Load()
  348.     On Error Resume Next 'Hide exceptions
  349.     'Connect to application server
  350.     'Use IMSIGX.Application.4 for inproc (DLL) server
  351.     'Use TurboCAD.Application.4 for local (EXE) server
  352.     Set TheApp = CreateObject("IMSIGX.Application.4")
  353.     If TheApp Is Nothing Then
  354.         MsgBox "Could not start server.  " & Err.Description & "  Quitting."
  355.         End
  356.     Else
  357.         Set Drawings = TheApp.Drawings
  358.         If Drawings Is Nothing Then
  359.             MsgBox "Bad server.  " & Err.Description & "  Quitting"
  360.             End
  361.         End If
  362.     End If
  363. End Sub
  364. Private Function UnselectAll() As Boolean
  365.     Dim PenColor As Object
  366.     If Not (SelectedGraphic Is Nothing) Then
  367.         Set PenColor = SelectedGraphic.Properties("PenColor")
  368.         PenColor.Value = SavedColor
  369.         Set SelectedGraphic = Nothing
  370.         UnselectAll = True
  371.     Else
  372.         UnselectAll = False
  373.     End If
  374. End Function
  375. Public Sub KillModes()
  376.     If ActiveTool$ <> "" Then
  377.         Toolbar1.Buttons(ActiveTool$).Value = tbrUnpressed
  378.         ActiveTool$ = ""
  379.     End If
  380.     If UnselectAll Then Repaint
  381.     Set SplineVerts = Nothing
  382.     Set SplineGraphic = Nothing
  383.     LeftButtonDown = False
  384.     Dragging = False
  385. End Sub
  386. Public Sub ReleaseDrawingObjects()
  387.     KillModes
  388.     'Update the status bar
  389.     StatusBar1.Panels(1).Text = "No drawing"
  390.     Set TheView = Nothing
  391.     Set Views = Nothing
  392.     Picture1.BackColor = vbWindowBackground
  393.     If Not (TheDrawing Is Nothing) Then
  394.         TheDrawing.Close
  395.         Set TheDrawing = Nothing
  396.     End If
  397. End Sub
  398. 'Painting
  399. Private Sub Repaint()
  400.     Picture1.Refresh
  401. End Sub
  402. 'Zooming
  403. Private Sub ViewZoomBy(Factor#)
  404.     TheView.Update = False
  405.     TheView.hWnd = Picture1.hWnd
  406.     TheView.MappingMode = 1
  407.     TheView.Margins = False
  408.     TheView.FixedAspectRatio = True
  409.     Dim ViewChanged As Boolean
  410.     Dim ZoomIt As Boolean
  411.     If Factor# <= 0# Or (ViewW# = 0 And ViewW# = 0) Then
  412.         'Factor# <= 0# means reset.  Otherwise, initial settings
  413.         TheView.ScreenLeft = Picture1.ScaleLeft
  414.         TheView.ScreenTop = Picture1.ScaleTop
  415.         TheView.ScreenWidth = Picture1.ScaleWidth
  416.         TheView.ScreenHeight = Picture1.ScaleHeight
  417.         ViewL# = TheView.ViewLeft
  418.         ViewT# = TheView.ViewTop
  419.         ViewW# = TheView.ViewWidth
  420.         ViewH# = TheView.ViewHeight
  421.         ZoomIt = True
  422.         ViewChanged = True
  423.     End If
  424.     If Factor# > 0# And Factor <> 1# Then
  425.         'Keep the center fixed, and change the view coordinates
  426.         Dim ViewCenterX#, ViewCenterY#
  427.         ViewCenterX# = ViewL# + (ViewW# / 2#)
  428.         ViewCenterY# = ViewT# - (ViewH# / 2#)
  429.         ViewW# = ViewW# / Factor#
  430.         ViewH# = ViewH# / Factor#
  431.         ViewL# = ViewCenterX# - (ViewW# / 2#)
  432.         ViewT# = ViewCenterY# + (ViewH# / 2#)
  433.         ViewChanged = True
  434.     End If
  435.     'Synchronize the view
  436.     TheView.ViewLeft = ViewL#
  437.     TheView.ViewTop = ViewT#
  438.     TheView.ViewWidth = ViewW#
  439.     TheView.ViewHeight = ViewH#
  440.     If ZoomIt Then
  441.         TheView.ZoomToExtents
  442.     End If
  443.     Repaint 'Update display
  444.     If ViewChanged Then
  445.         UpdateScrollParams
  446.     End If
  447. End Sub
  448. Private Sub Form_Unload(Cancel As Integer)
  449.     ReleaseDrawingObjects
  450.     Set Drawings = Nothing
  451.     Set TheApp = Nothing
  452. End Sub
  453. 'Scrolling
  454. Private Sub UpdateScrollParams()
  455.     'Min always 0
  456.     'Max always 32000
  457.     'LargeChange always 320
  458.     'SmallChange always 32
  459.     'Default values
  460.     ScrollCenterX# = 0#
  461.     ScrollCenterY# = 0#
  462.     ScrollRangeX# = 1#
  463.     ScrollRangeY# = 1#
  464.     Dim X1#, Y1#, X2#, Y2#
  465.     X1# = ViewL#
  466.     Y1# = ViewT# - ViewH#
  467.     X2# = ViewL# + ViewW#
  468.     Y2# = ViewT#
  469.     On Error GoTo Errors
  470.     If Not (TheDrawing Is Nothing) Then
  471.         'Set scroll center to center of drawing's
  472.         'X-Y bounding box
  473.         Dim Graphics As Object
  474.         Dim BBox As Object
  475.         Dim BoxMin As Object
  476.         Dim BoxMax As Object
  477.         Set Graphics = TheDrawing.Graphics
  478.         Set BBox = Graphics.CalcBoundingBox
  479.         Set BoxMin = BBox.Min
  480.         Set BoxMax = BBox.Max
  481.         X1# = BoxMin.X
  482.         Y1# = BoxMin.Y
  483.         X2# = BoxMax.X
  484.         Y2# = BoxMax.Y
  485.         ScrollCenterX# = (X1# + X2#) / 2#
  486.         ScrollCenterY# = (Y1# + Y2#) / 2#
  487.         
  488.         'Expand bounding box to include current viewport
  489.         If ViewL# < X1# Then X1# = ViewL#
  490.         If (ViewT# - ViewH#) < Y1# Then Y1# = ViewT# - ViewH#
  491.         If (ViewL# + ViewW#) > X2# Then X2# = ViewL# + ViewW#
  492.         If ViewT# > Y2# Then Y2# = ViewT#
  493.     End If
  494. Errors:
  495.     'Now set scroll range based on bounding box
  496.     Dim Delta1#, Delta2# 'Either side of center
  497.     Delta1# = ScrollCenterX# - X1#
  498.     Delta2# = X2# - ScrollCenterX#
  499.     If Delta1# > Delta2# Then
  500.         ScrollRangeX# = 2# * Delta1#
  501.     Else
  502.         ScrollRangeX# = 2# * Delta2#
  503.     End If
  504.     Delta1# = ScrollCenterY# - Y1#
  505.     Delta2# = Y2# - ScrollCenterY#
  506.     If Delta1# > Delta2# Then
  507.         ScrollRangeY# = 2# * Delta1#
  508.     Else
  509.         ScrollRangeY# = 2# * Delta2#
  510.     End If
  511.     'Update controls with these values
  512.     SetScrollValues
  513. End Sub
  514. 'Update HScroll1 and VScroll1 controls with global values
  515. Private Sub SetScrollValues()
  516.     Dim ScrollVal%
  517.     Dim DValue#, DMax# 'Scrollbar value, max as doubles
  518.     Dim ViewC# 'Center of view
  519.     'We set the values proportionally
  520.     If ScrollRangeX# > 0# Then
  521.         DMax# = HScroll1.Max
  522.         ViewC# = ViewL# + (ViewW# / 2#)
  523.         DValue# = (DMax# / 2#) + DMax# * (ViewC# - ScrollCenterX#) / ScrollRangeX#
  524.         If DValue# < 0# Then
  525.             ScrollVal% = 0
  526.         ElseIf DValue# > DMax# Then
  527.             ScrollVal% = HScroll1.Max
  528.         Else
  529.             ScrollVal% = DValue#
  530.         End If
  531.     Else
  532.         ScrollVal% = (HScroll1.Min + HScroll1.Max) / 2
  533.     End If
  534.     HScroll1.Value = ScrollVal%
  535.     HScrollLast% = ScrollVal% 'Remember last value
  536.     If ScrollRangeY# > 0# Then
  537.         DMax# = VScroll1.Max
  538.         ViewC# = ViewT# - (ViewH# / 2#)
  539.         DValue# = (DMax# / 2#) + DMax# * (ViewC# - ScrollCenterY#) / ScrollRangeY#
  540.         If DValue# < 0# Then
  541.             ScrollVal% = 0
  542.         ElseIf DValue# > DMax# Then
  543.             ScrollVal% = VScroll1.Max
  544.         Else
  545.             ScrollVal% = DValue#
  546.         End If
  547.     Else
  548.         ScrollVal% = (VScroll1.Min + VScroll1.Max) / 2
  549.     End If
  550.     VScroll1.Value = ScrollVal%
  551.     VScrollLast% = ScrollVal% 'Remember last value
  552. End Sub
  553. 'Change the viewport parameters after a scroll
  554. Private Sub ViewScrollBy(DeltaX#, DeltaY#)
  555.     ViewL# = ViewL# + DeltaX#
  556.     ViewT# = ViewT# + DeltaY#
  557.     ViewZoomBy 1#
  558. End Sub
  559. Private Sub UpdateHScroll()
  560.     Dim ScrollVal%
  561.     ScrollVal% = HScroll1.Value
  562.     If (ScrollVal% <> HScrollLast%) And Not (TheDrawing Is Nothing Or TheView Is Nothing) Then
  563.         Dim Range#
  564.         Dim Delta#
  565.         Range# = HScroll1.Max - HScroll1.Min
  566.         Delta# = ScrollVal% - HScrollLast%
  567.         Delta# = Delta# * ViewW# / Range#
  568.         ViewScrollBy Delta#, 0#
  569.     End If
  570.     HScrollLast% = ScrollVal% 'Remember last value
  571. End Sub
  572. Private Sub UpdateVScroll()
  573.     Dim ScrollVal%
  574.     ScrollVal% = VScroll1.Value
  575.     If (ScrollVal% <> VScrollLast%) And Not (TheDrawing Is Nothing Or TheView Is Nothing) Then
  576.         Dim Range#
  577.         Dim Delta#
  578.         Range# = VScroll1.Max - VScroll1.Min
  579.         Delta# = ScrollVal% - VScrollLast%
  580.         Delta# = -Delta# * ViewH# / Range#
  581.         ViewScrollBy 0#, Delta#
  582.     End If
  583.     VScrollLast% = ScrollVal% 'Remember last value
  584. End Sub
  585. 'Scroll handlers
  586. Private Sub HScroll1_Change()
  587.     UpdateHScroll
  588. End Sub
  589. Private Sub HScroll1_Scroll()
  590.     UpdateHScroll
  591. End Sub
  592. Private Function MyFormat(Val#) As String
  593.     Dim Log10#
  594.     Log10# = Log(Abs(Val#)) / Log(10#)
  595.     If (Log10# > 5#) Or (Log10# < -3#) Then
  596.         MyFormat = Format(Val#, "0.00E-00")
  597.     Else
  598.         MyFormat = Format(Val#, "0.0###")
  599.     End If
  600. End Function
  601. Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  602.     If (Button And 1) = 0 Then Exit Sub 'Only care about left button
  603.     Dragging = False
  604.     LeftButtonDown = True
  605.     Dim NeedRepaint As Boolean
  606.     Dim PickResult As Object
  607.     Dim PickCount%
  608.     Dim PenColor As Object 'Property object
  609.     Dim Graphics As Object
  610.     Dim CurX#, CurY#
  611.     On Error GoTo Errors
  612.     If Not (TheDrawing Is Nothing Or TheView Is Nothing) Then
  613.         CurX# = X
  614.         CurY# = Y
  615.         TheView.ScreenToView CurX#, CurY#, StartX#, StartY#
  616.         Select Case ActiveTool$
  617.             Case "Star"
  618.                 Set Graphics = TheDrawing.Graphics
  619.                 Graphics.AddStar StartX#, StartY#, 0#
  620.             Case "Select"
  621.                 Set PickResult = TheView.PickPoint(StartX#, StartY#, 0.1)
  622.                 PickCount% = PickResult.Count
  623.                 NeedRepaint = UnselectAll
  624.                 If PickCount% > 0 Then
  625.                     Set SelectedGraphic = PickResult(0).Graphic
  626.                     Set PenColor = SelectedGraphic.Properties("PenColor")
  627.                     SavedColor = PenColor.Value
  628.                     PenColor.Value = &HFF00FF 'Magenta
  629.                     NeedRepaint = True
  630.                 End If
  631.                 If NeedRepaint Then Repaint
  632.         End Select
  633.     End If
  634. Errors:
  635. End Sub
  636. Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  637.     If (Button And 1) = 0 Then Exit Sub 'Only care about left button
  638.     If Not LeftButtonDown Then Exit Sub 'Only if left button was down
  639.     Dragging = True
  640. End Sub
  641. Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  642.     If (Button And 1) = 0 Then Exit Sub 'Only care about left button
  643.     If Not LeftButtonDown Then Exit Sub
  644.     Dim Graphics As Object
  645.     Dim CurX#, CurY#
  646.     Dim VX#, VY# 'Mouse coordinates in view space
  647.     On Error GoTo Errors
  648.     If Not (TheDrawing Is Nothing Or TheView Is Nothing) Then
  649.         Set Graphics = TheDrawing.Graphics
  650.         If ActiveTool$ <> "" Then
  651.             CurX# = X
  652.             CurY# = Y
  653.             TheView.ScreenToView CurX#, CurY#, VX#, VY#
  654.             Select Case ActiveTool$
  655.                 Case "Circle"
  656.                     Graphics.AddCircleCenterAndPoint StartX#, StartY#, 0#, VX#, VY#, 0#
  657.                     TheView.Update = True
  658.                 Case "Line"
  659.                     Graphics.AddLineSingle StartX#, StartY#, 0#, VX#, VY#, 0#
  660.                     TheView.Update = True
  661.                 Case "Curve"
  662.                     If SplineGraphic Is Nothing Then
  663.                         Set SplineGraphic = Graphics.AddCurveSpline(StartX#, StartY#, 0#)
  664.                         Set SplineVerts = SplineGraphic.Vertices
  665.                     End If
  666.                     If Not (SplineVerts Is Nothing) Then SplineVerts.Add VX#, VY#, 0#
  667.                     Repaint
  668.                 Case Else
  669.             End Select
  670.         End If
  671.     End If
  672.     Set Graphics = Nothing
  673.     LeftButtonDown = False
  674.     Dragging = False
  675.     Exit Sub
  676. Errors:
  677.     Set SplineVerts = Nothing
  678.     Set SplineGraphic = Nothing
  679.     Set Graphics = Nothing
  680.     LeftButtonDown = False
  681.     Dragging = False
  682. End Sub
  683. Private Sub Picture1_Paint()
  684.     If Not (TheView Is Nothing) Then
  685.         TheView.Update = False
  686.         TheView.hWnd = Picture1.hWnd
  687.         TheView.MappingMode = 1
  688.         TheView.Margins = False
  689.         TheView.FixedAspectRatio = True
  690.         If (ViewW# = 0#) And (ViewH# = 0#) Then
  691.             'Initial settings
  692.             TheView.ScreenLeft = Picture1.ScaleLeft
  693.             TheView.ScreenTop = Picture1.ScaleTop
  694.             TheView.ScreenWidth = Picture1.ScaleWidth
  695.             TheView.ScreenHeight = Picture1.ScaleHeight
  696.             TheView.ZoomToExtents
  697.         Else
  698.             'Saved settings
  699.             TheView.Refresh
  700.         End If
  701.         
  702.         'Update globals
  703.         ViewL# = TheView.ViewLeft
  704.         ViewT# = TheView.ViewTop
  705.         ViewW# = TheView.ViewWidth
  706.         ViewH# = TheView.ViewHeight
  707.         'Feedback in status bar
  708.         StatusBar1.Panels(2).Text = MyFormat(ViewL#)
  709.         StatusBar1.Panels(3).Text = MyFormat(ViewT#)
  710.         StatusBar1.Panels(4).Text = MyFormat(ViewW#)
  711.         StatusBar1.Panels(5).Text = MyFormat(ViewH#)
  712.     Else
  713.         'Feedback in status bar
  714.         StatusBar1.Panels(2).Text = "Left"
  715.         StatusBar1.Panels(3).Text = "Top"
  716.         StatusBar1.Panels(4).Text = "Width"
  717.         StatusBar1.Panels(5).Text = "Height"
  718.     End If
  719. End Sub
  720. Private Sub Toolbar1_ButtonClick(ByVal Button As Button)
  721.     KillModes
  722.     ActiveTool$ = Button.Key
  723. End Sub
  724. Private Sub VScroll1_Change()
  725.     UpdateVScroll
  726. End Sub
  727. Private Sub VScroll1_Scroll()
  728.     UpdateVScroll
  729. End Sub
  730.